package org.az.netty_study.p03_nio组件之selector._3_单线程selector;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;

/**
 * 可写事件的客户端
 */
public class WriteClient {
    public static void main(String[] args) throws IOException {
        SocketChannel sc = SocketChannel.open();
        sc.connect(new InetSocketAddress("localhost", 9996));

        ByteBuffer buffer = ByteBuffer.allocate(1024 * 1024);
        //接收服务器发给客户端的数据
        int count = 0;
        while (true) {
            //一次没读完，下次进入循环可以接着读；如果读完了，则阻塞(因为没有调用configureBlocking(false))
            count += sc.read(buffer);
            System.out.println("读取到的字节数为:" + count);
            buffer.clear();
        }
    }
}
